import './theme/index.scss'
import Clipboard from 'clipboard'
import * as PackageList from './index-package'
import { local, session, Type, Tools, Watermark, eventMonitor } from './script/index'

export * from './script/index'
export * from './index-package'
export default {
  install (Vue, { prefix = 'Me' } = {}) {
    for (const key in PackageList) {
      Vue.component(`${prefix}${key}`, Reflect.get(PackageList, key))
    }

    Vue.prototype.$copy = function (target, { prompt = false, message = '复制成功' } = {}) {
      const clipboard = new Clipboard(target)
      clipboard.on('success', () => {
        if (prompt === true) {
          this.$message.info(message)
        } else {
          console.info('Clipboard ----> copy error：', message)
        }
        clipboard.destroy()
      })
      clipboard.on('error', () => {
        const message = '该浏览器不支持自动复制'
        if (prompt === true) {
          this.$message.error(message)
        } else {
          console.warn('Clipboard ----> copy error：', message)
        }
        clipboard.destroy()
      })
    }

    const { Dialog, Message } = PackageList
    Vue.prototype.$dialog = Dialog
    Vue.prototype.$message = Message
    Vue.prototype.$watermark = new Watermark()
    Vue.prototype.$type = Type
    Vue.prototype.$tools = Tools
    Vue.prototype.$local = local
    Vue.prototype.$session = session
    Vue.prototype.$eventMonitor = eventMonitor
    Vue.prototype.$mePrefix = prefix.toLowerCase()
  }
}
